//
//  SearchViewController.m
//  必争医疗
//
//  Created by 8号球 on 14-11-19.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "SearchViewController.h"
#import "SearchHistoryViewController.h"
#import "CommonDiseaseViewController.h"
@interface SearchViewController ()<UISearchBarDelegate>

@end

@implementation SearchViewController
- (void)dealloc
{
    [_mysearch release];
    [_search release];
    [_ill release];
    [_medicine release];
    [_office release];
    [_hospital release];
    [_shop release];
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor whiteColor]];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"自查";

    //执行方法
    [self creatSearchBar];
    [self creatSelfSearchButton];
    [self creatDiseaseButton];
    [self creatMedicineButton];
    [self creatOfficeButton];
    [self creatHospitalButton];
    [self creatShopButton];
    [self creatAdvertisement];
}

#pragma mark -
#pragma mark 创建UISearchBar
- (void)creatSearchBar
{
    self.mysearch = [[UISearchBar alloc] initWithFrame:CGRectMake(20, 20, self.view.frame.size.width - 40, self.view.frame.size.height / 18)];
    [_mysearch setPlaceholder:@"查询药品、疾病、症状、医生等"];
    [_mysearch setBarStyle:UIBarStyleDefault];
    [_mysearch setTintColor:[UIColor clearColor]];
    [_mysearch resignFirstResponder];
    _mysearch.delegate = self;
    [self.view addSubview:_mysearch];
}

//跳转到搜索历史页面
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    SearchHistoryViewController *history = [[[SearchHistoryViewController alloc] init] autorelease];
    [self.navigationController pushViewController:history animated:YES];
    return NO;
}



#pragma mark -
#pragma mark 创建症状自查按钮
- (void)creatSelfSearchButton
{
    
    self.search = [UIButton buttonWithType:UIButtonTypeCustom];
    [_search setFrame:CGRectMake(0, _mysearch.frame.origin.y + _mysearch.frame.size.height + 20, self.view.frame.size.width / 3, self.view.frame.size.width / 3)];
    [_search setBackgroundColor:[UIColor yellowColor]];
    
    [self.view addSubview:_search];

}

#pragma mark -
#pragma mark 创建常见病按钮
- (void)creatDiseaseButton
{
    
    self.ill = [UIButton buttonWithType:UIButtonTypeCustom];
    [_ill setFrame:CGRectMake(_search.frame.size.width, _mysearch.frame.origin.y + _mysearch.frame.size.height + 20, self.view.frame.size.width / 3, self.view.frame.size.width / 3)];
    [_ill setBackgroundColor:[UIColor redColor]];
    [_ill addTarget:self action:@selector(toDiseaseView) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_ill];
}

//跳转到常见病详情页面
- (void)toDiseaseView
{
    CommonDiseaseViewController *disease = [[[CommonDiseaseViewController alloc] init] autorelease];
    [self.navigationController pushViewController:disease animated:YES];
}





#pragma mark -
#pragma mark 创建常见药按钮
- (void)creatMedicineButton
{
    
    self.medicine = [UIButton buttonWithType:UIButtonTypeCustom];
    [_medicine setFrame:CGRectMake(_ill.frame.size.width * 2, _mysearch.frame.origin.y + _mysearch.frame.size.height + 20, self.view.frame.size.width / 3, self.view.frame.size.width / 3)];
    [_medicine setBackgroundColor:[UIColor blackColor]];
    
    [self.view addSubview:_medicine];
    
}

#pragma mark -
#pragma mark 创建科室问题按钮
- (void)creatOfficeButton
{
    
    self.office = [UIButton buttonWithType:UIButtonTypeCustom];
    [_office setFrame:CGRectMake(0, _search.frame.origin.y + _search.frame.size.height, self.view.frame.size.width / 3, self.view.frame.size.width / 3)];
    [_office setBackgroundColor:[UIColor cyanColor]];
    
    [self.view addSubview:_office];
    
}


#pragma mark -
#pragma mark 创建附近医院按钮
- (void)creatHospitalButton
{
    
    self.hospital = [UIButton buttonWithType:UIButtonTypeCustom];
    [_hospital setFrame:CGRectMake(_office.frame.size.width, _search.frame.origin.y + _search.frame.size.height, self.view.frame.size.width / 3, self.view.frame.size.width / 3)];
    [_hospital setBackgroundColor:[UIColor grayColor]];
    
    [self.view addSubview:_hospital];
    
}


#pragma mark -
#pragma mark 创建附近药店按钮
- (void)creatShopButton
{
    
    self.shop = [UIButton buttonWithType:UIButtonTypeCustom];
    [_shop setFrame:CGRectMake(_office.frame.size.width * 2, _search.frame.origin.y + _search.frame.size.height, self.view.frame.size.width / 3, self.view.frame.size.width / 3)];
    [_shop setBackgroundColor:[UIColor redColor]];
    
    [self.view addSubview:_shop];
    
}

#pragma mark -
#pragma mark 创建广告
- (void)creatAdvertisement
{
    UIImageView *ad = [[UIImageView alloc] initWithFrame:CGRectMake(5, _shop.frame.origin.y + _shop.frame.size.height + 10, self.view.frame.size.width - 10, self.view.frame.size.height / 6)];
    
    [ad setBackgroundColor:[UIColor grayColor]];
    
    [self.view addSubview:ad];
}


- (void)viewWillAppear:(BOOL)animated
{
    [self.tabBarController.tabBar setHidden:NO];
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
